package sortAlgorithm;

import java.util.Arrays;
import java.util.Random;

public class SelectionSort {
	public static void main(String[] args) {
		Random random = new Random();
		int n = 10;
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = random.nextInt(20);
		}
		System.out.println(Arrays.toString(a));
		selectionSort(a);
		System.out.println(Arrays.toString(a));
	}

	/**
	 * 从小到大
	 *
	 * @param array 要排序的数组
	 */
	public static void selectionSort(int[] array) {
		for (int i = 0; i < array.length - 1; i++) {
			for (int j = i + 1; j < array.length; j++) {
				if (array[i] > array[j]) {
					int temp = array[i];
					array[i] = array[j];
					array[j] = temp;
				}
			}
		}
	}

}
